package com.bite.friend.domain.user;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.bite.common.core.domain.BaseEntity;
import com.bite.common.core.enums.UserStatus;
import com.bite.friend.domain.user.dto.UserEditDTO;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import lombok.Getter;
import lombok.Setter;

/**
 * @TableName tb_user
 */
@TableName(value ="tb_user")
@Getter
@Setter
public class User extends BaseEntity {
    @TableId(type = IdType.ASSIGN_ID)
    @JsonSerialize(using = ToStringSerializer.class)
    private Long userId;

    private String avatar;

    private String nickName;

    private String phone;

    private String password;

    private String wechat;

    private String email;

    private String schoolName;

    private String majorName;

    private Integer status;

    private String introduce;

    private Integer sex;

    public static User createByPhone(String phone) {
        User user = new User();
        user.setPhone(phone);
        user.setNickName(phone.substring(0, 3) + "****" + phone.substring(7));
        user.setStatus(UserStatus.NORMAL.getValue());
        return user;
    }

    public static User createByDTO(UserEditDTO userEditDTO) {
        User user = new User();
        BeanUtil.copyProperties(userEditDTO, user);
        return user;
    }
}
